@echo off

@if "%1"=="" (
   @echo usage: %~n0 {certificate subject name}
   @goto :end
)

@set CERTFILE="%~dp0%1.cer"

if NOT EXIST %CERTFILE% (
  goto :end
)

set CERTHASH=

for /f "tokens=2,* usebackq" %%a in ( `certutil -dump %CERTFILE% ^| findstr /c:"Cert Hash(sha1)"` ) do (
    set CERTHASH=%%b
)

@if NOT "%CERTHASH%" == "" (
 set CERTHASH=%CERTHASH: =%
)

set %1CERTHASH=%CERTHASH%

:end
